package com.sky.controller.common;

import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

/**
 * packageName com.sky.common
 *
 * @author fenglai
 * @version JDK 11
 * @className CommonController
 * @date 2023/12/15
 * @description TODO
 */
@RestController
@RequestMapping("/admin/common")
@Api("通用功能模块")
@Slf4j
public class CommonController {
    @Autowired
    private AliOssUtil aliOssUtil;

    @PostMapping("/upload")
    @ApiOperation("文件上传功能")
    public Result<String> upload(MultipartFile file) throws IOException {

        String name = file.getOriginalFilename();

        name = UUID.randomUUID() + name.substring(name.lastIndexOf("."));

        String url = aliOssUtil.upload(file.getBytes(), name);

        return Result.success(url);

    }


}